package leetcode.weekly.week326;

//Solution3Test
public class Solution3 {

//	输入：s = "165462", k = 60
//	输出：4

	public int minimumPartition(String s, int k) {
		char[] cs = s.toCharArray();
		int ans = 0;
		long num = -1l;
		for (int i = 0; i < s.length(); i++) {
			int cur = cs[i] - '0';
			if (num == -1) {
				num = cur;
				if (num > k) {
					return -1;
				}
			} else {
				if (num > k) {
					return -1;
				}
				if (num * 10 + cur > k) {
					ans++;
					num = cur;
				} else {
					num = num * 10 + cur;
				}
			}
		}
		if (num != -1 && num <= k) {
			ans++;
		}
		return ans;
	}
}
